/*
*@file tooltip.js
*@author ahmed atta
*  Include some functions of tooltip event based on DIV
	<div class="hint">
          <div id="hint_center">
                  <p></p>
            </div>
    </div>
*/
//=========================================//
/*
** Tooltip
*
*/
$(document).ready(function () {
      var i = 0;
      var _hint = $(".hint");
      _hint.css("opacity", 0);
      $('.hover').css("opacity", 0);

      function get_item_hint(ele_em) {
            //call hint bar
            var hint_text = ele_em.html();
            var ele_p = $("div#hint_center > p");
            // change without animation
            // $("div#center").css("width", $em.width());
            //change with animation
            //stop any animation
            $("div#hint_center").stop();
            ele_p.html('');
            ele_p.fadeOut("fast");
            $("div#hint_center").animate({ width: ele_em.width() }, "normal", function () {
                $("div#hint_center > p").html(hint_text);
                ele_p.fadeIn("fast", function () { ele_p.css("opacity", 1); ele_p.css("padding", "0 0 0 0"); });
             });
      }
	function showtip($obj, $em) {
            var ele_pos = $obj.offset();
			var hint_pos = $(".hint").offset();
            var x = ele_pos.left - 150;
			var _top = ele_pos.top - hint_pos.top;
			//alert(ele_pos.top);
            //$em.css("left", x);
            $em.animate({ top: 80, left: x, opacity: 1 }, "normal");
    }
    function hidetip($obj, $em) {
            var pos = $obj.offset();
            var x = pos.left - 10;
            $em.css("left", x);
            $em.animate({ top: 100, opacity: 0 }, "fast");
    }
    $("span.tooltip").each(function(){ 
			//call hint tool    "#u_hejriDate"
			$(this).hover(function () {                       
								var ele_em = $(this).next("em");
								_hint.stop();
								get_item_hint(ele_em);
								showtip($(this), _hint);
                            }, 
                           function () {
                                var ele_em = $(this).next("em");
                                _hint.stop();
                                hidetip($(this), _hint);
                });

    });  
});
